package zozopo.warehouse;

import java.io.UnsupportedEncodingException;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts2.interceptor.ServletRequestAware;
import org.apache.struts2.interceptor.ServletResponseAware;
import org.apache.struts2.interceptor.SessionAware;

import zozopo.background.operator.operations.OperatorTB;
import zozopo.background.operator.operations.OperatorlimitedTB;
import zozopo.user.operations.UserTB;
import zozopo.warehouse.operations.ReceiptlistOS;

import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionSupport;

public class ChangeShipNoAction extends ActionSupport implements Action,SessionAware,ServletRequestAware,ServletResponseAware{
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	private static final String limitedCode ="FLOW.WAREHOUSE.RECEIPTLIST";
	
	
	//传入参数
	private int receiptlistid;

	private String shipno;

	//传出参数
	private String responseText  = "";

	
	HttpServletRequest request;
	HttpServletResponse response;
	private Map<Object, Object> session;
	

	
	
	
	public void setServletRequest(HttpServletRequest arg0) {
		// TODO Auto-generated method stub
		request = arg0;
	}

	public void setSession(Map arg0) {
		// TODO Auto-generated method stub
		session = arg0;
	}

	

	public void setServletResponse(HttpServletResponse arg0) {
		// TODO Auto-generated method stub
		response = arg0;
		response.setCharacterEncoding("UTF-8");
		response.setContentType("application/json; charset=UTF-8");
	}
	
	public String execute(){
		 
		ReceiptlistOS receiptlistOS = new ReceiptlistOS();
			
		if(receiptlistOS.updateForShipno(receiptlistid, shipno)){
			responseText="单号:" + receiptlistid + " 快递单号已经修改成功!";
		}
			
		receiptlistOS.releaseConnection();
		
		
		return SUCCESS;
	}
	
	public void validate() {
		
		//权限处理
		OperatorTB operator = (OperatorTB)session.get("operatorInfo"); 
	
		if(operator == null){
			addFieldError("errormessage",getText("operator.timeoutornotlogin"));
			return ; 
		} 
		
		//用户权限
		Map<String,OperatorlimitedTB> operatorlimitedMap = (Map<String,OperatorlimitedTB>)session.get("operatorlimitedMap");
		
		if(operatorlimitedMap.get(limitedCode) == null){
			addFieldError("errormessage","用户没有确认快递费用权限.");
			return;
		}
	} 
	
	

	public int getReceiptlistid() {
		return receiptlistid;
	}

	public void setReceiptlistid(int receiptlistid) {
		this.receiptlistid = receiptlistid;
	}

	public String getShipno() {
		return shipno;
	}

	public void setShipno(String shipno) throws UnsupportedEncodingException {
		this.shipno = java.net.URLDecoder.decode(shipno, "UTF-8");
	}

	public String getResponseText() {
		return responseText;
	}

	public void setResponseText(String responseText) {
		this.responseText = responseText;
	}

	public static String getLimitedcode() {
		return limitedCode;
	}


	

}
